import 'package:flutter/material.dart';
import 'package:flutter_learn/view/web_view_page.dart';

class WebPage extends StatefulWidget {
  WebPage(this.title, {Key key}) : super(key: key);
  final String title;
  @override
  _WebPageState createState() => _WebPageState();
}

class _WebPageState extends State<WebPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Container(
            padding: const EdgeInsets.all(10),
            child: ListView(
              scrollDirection: Axis.vertical, // 水平listView
              children: <Widget>[
                ButtonBar(
                  alignment:
                      MainAxisAlignment.start, //布局方向，默认MainAxisAlignment.end
                  mainAxisSize: MainAxisSize.min, //主轴大小，默认MainAxisSize.max
                  children: <Widget>[
                    RaisedButton(
                      child: Text('访问百度'),
                      onPressed: () => {gotoBaidu(context)},
                    ),
                    RaisedButton(
                      child: Text('访问我的Github'),
                      onPressed: () => {gotoGithub(context)},
                    ),
                    RaisedButton(
                      child: Text('访问我的博客'),
                      onPressed: () => {gotoBlog(context)},
                    ),
                  ],
                ),
              ],
            )));
  }

  void gotoBaidu(BuildContext context) {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return WebViewPage("https://www.baidu.com/", "百度");
    }));
  }

  void gotoGithub(BuildContext context) {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return WebViewPage("https://github.com/xuexiangjys", "Github");
    }));
  }

   void gotoBlog(BuildContext context) {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return WebViewPage("https://juejin.im/user/598feef55188257d592e56ed", "博客");
    }));
  }
}
